// 还可以替换类的构造函数
// 可通过返回一个新的构造函数来替换原有的构造函数
function switchConstructor<T extends {new(...args:any[])}>(constructor:T){
    return class extends constructor{
        constructor(...args){
            super(...args)
            console.log('instance created');
            this.name = '小张'
        }
    }
}

@switchConstructor
class User{
    constructor(public name:string){
        console.log('User created');
    }
}
const info = new User('小明');
console.log(info.name);
